package cn.mygweb.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.thymeleaf.util.StringUtils;

import cn.mygweb.admin.modules.web.pojo.Columns;
import cn.mygweb.admin.modules.web.service.ColumnsService;
import cn.mygweb.common.controller.BaseController;
import cn.mygweb.common.pojo.RedisKey;
import cn.mygweb.common.service.SysVisitService;
import cn.mygweb.common.utils.JsonUtils;
import cn.mygweb.common.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;

/** 
* <p>Title: WebIndexController.java</p>
* <p>Description: 网站前台主页</p>  
* @author gxb 
* @date 2019年5月25日 
* <p>Copyright: Copyright (c) 2019</p>
* <p>Company: www.mygweb.cn</p> 
*/ 
@Controller
//@RequestMapping("/web")
@Slf4j
public class WebIndexController extends BaseController{
	
	/**
	 * <p>Title: index</p>
	 * <p>Description: 访问网站首页</p>
	 * @return
	 */
	//输入网址直接访问index页面，不需要加其他内容
	@RequestMapping("")
	public String index(ModelMap model) {
		sysVisitService.AddOneCount(1);
		//redis缓存
		List<Columns> columnsList;
		try {
			if(super.isNullOrBlank(RedisKey.KEY_WEB_INDEX)) {
				columnsList = columnsService.queryListByExample(new Columns());
				super.redisSet(RedisKey.KEY_WEB_INDEX, JsonUtils.objectToJson(columnsList));
			}
			columnsList = JsonUtils.jsonToList(super.redisGet(RedisKey.KEY_WEB_INDEX), Columns.class);
		} catch (Exception e) {
			e.printStackTrace();
			columnsList = columnsService.queryListByExample(new Columns());
		}
		model.addAttribute("columnsList", columnsList);
		return "web/index";
	}
	
}
